package com.future.dao;

import java.sql.Connection;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.future.model.po.FirstFillBlankModel;

public class FirstFillBlankDAO extends BaseDAO<FirstFillBlankModel> {
	private static Logger logger = LogManager.getLogger(FirstFillBlankDAO.class);

	public FirstFillBlankDAO() {

	}

	public FirstFillBlankDAO(Connection conn) {
		super(conn);
	}

	public boolean save(FirstFillBlankModel model) {
		String sql = "insert into firstfillblank (userid,item0101,item0102,item0103,item0104,item0201,item0202,"
				+ "item0203,item0204,item0205,item0206,item0207,item0208,item0301,item0302,item0401,item0402,item0501,"
				+ "item0502,item0503,item0601,item0602,item0701,item0702,item0703,item0704,item0705,item0706,item0707,"
				+ "item0708,item0709,item0710,item0801,item0802,item0803,item0804,item0805,item0806,item0901,item0902,"
				+ "item0903,item0904) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
		return this.update(sql, model.getUserId(), model.getItem0101(), model.getItem0102(), model.getItem0103(),
				model.getItem0104(), model.getItem0201(), model.getItem0202(), model.getItem0203(), model.getItem0204(),
				model.getItem0205(), model.getItem0206(), model.getItem0207(), model.getItem0208(), model.getItem0301(),
				model.getItem0302(), model.getItem0401(), model.getItem0402(), model.getItem0501(), model.getItem0502(),
				model.getItem0503(), model.getItem0601(), model.getItem0602(), model.getItem0701(), model.getItem0702(),
				model.getItem0703(), model.getItem0704(), model.getItem0705(), model.getItem0706(), model.getItem0707(),
				model.getItem0708(), model.getItem0709(), model.getItem0710(), model.getItem0801(), model.getItem0802(),
				model.getItem0803(), model.getItem0804(), model.getItem0805(), model.getItem0806(), model.getItem0901(),
				model.getItem0902(), model.getItem0903(), model.getItem0904());
	}

	public List<FirstFillBlankModel> findAll() {
		String sql = "select * from firstfillblank ";
		return this.searchAsBeanList(sql, FirstFillBlankModel.class);
	}

	public List<FirstFillBlankModel> findByUserId(Integer userId) {
		FirstFillBlankModel model = new FirstFillBlankModel();
		model.setUserId(userId);
		return this.findByUserId(model);
	}

	public List<FirstFillBlankModel> findByUserId(FirstFillBlankModel model) {
		String sql = "select * from firstfillblank where userid = ?";
		return this.searchAsBeanList(sql, FirstFillBlankModel.class, model.getUserId());
	}

	public boolean modifyByUserId(FirstFillBlankModel model) {
		String sql = "update firstfillblank set item0101=?,item0102=?,item0103=?,item0104=?,item0201=?,"
				+ "item0202=?,item0203=?,item0204=?,item0205=?,item0206=?,item0207=?,item0208=?,item0301=?,"
				+ "item0302=?,item0401=?,item0402=?,item0501=?,item0502=?,item0503=?,item0601=?,item0602=?,"
				+ "item0701=?,item0702=?,item0703=?,item0704=?,item0705=?,item0706=?,item0707=?,item0708=?,"
				+ "item0709=?,item0710=?,item0801=?,item0802=?,item0803=?,item0804=?,item0805=?,item0806=?,"
				+ "item0901=?,item0902=?,item0903=?,item0904=? where userid = ?";
		logger.info("修改第一部分填空题sql="+sql);
		return this.update(sql, model.getItem0101(), model.getItem0102(), model.getItem0103(), model.getItem0104(),
				model.getItem0201(), model.getItem0202(), model.getItem0203(), model.getItem0204(), model.getItem0205(),
				model.getItem0206(), model.getItem0207(), model.getItem0208(), model.getItem0301(), model.getItem0302(),
				model.getItem0401(), model.getItem0402(), model.getItem0501(), model.getItem0502(), model.getItem0503(),
				model.getItem0601(), model.getItem0602(), model.getItem0701(), model.getItem0702(), model.getItem0703(),
				model.getItem0704(), model.getItem0705(), model.getItem0706(), model.getItem0707(), model.getItem0708(),
				model.getItem0709(), model.getItem0710(), model.getItem0801(), model.getItem0802(), model.getItem0803(),
				model.getItem0804(), model.getItem0805(), model.getItem0806(), model.getItem0901(), model.getItem0902(),
				model.getItem0903(), model.getItem0904(), model.getUserId());
	}

	public boolean deleteByUserId(Integer userId) {
		FirstFillBlankModel model = new FirstFillBlankModel();
		model.setUserId(userId);
		return deleteByUserId(model);
	}
	
	public boolean deleteByUserId(FirstFillBlankModel model) {
		String sql = "delete from firstfillblank where userid = ?";
		return this.update(sql, model.getUserId());
	}
}
